package dht.paxos;
import dht.HostAddress;
import dht.message.*;

public class OutstandingPrepareRequest implements OutstandingRequest {
    private final PrepareRequestMessage request;
    public OutstandingPrepareRequest(PrepareRequestMessage m) {
        this.request = m;
    }
    
    public HostAddress getAddress() {
        return request.getAddress();
    }
    
    public boolean isMatchingResponse(Message m) {
        if (!(m instanceof PrepareResponseMessage))
            return false;
        
        PrepareResponseMessage response = (PrepareResponseMessage)m;
        
        return request.getAddress().equals(response.getAddress())
            && request.getProposalNumber() == response.getProposalNumber();
    }
    
    
    public boolean isSameRequest(Message m) {
        if (!(m instanceof PrepareRequestMessage))
            return false;
        
        PrepareRequestMessage req = (PrepareRequestMessage)m;
        return request.getAddress().equals(req.getAddress())
            && request.getProposalNumber() == req.getProposalNumber();
    }
    
}
